void main() {
  // 需求：计算购物车数据中，被勾选商品的总价

  // 准备购物车数据
  List carts = [
    {"count": 2, "price": 10.0, "selected": true},
    {"count": 1, "price": 30.0, "selected": false},
    {"count": 5, "price": 20.0, "selected": true}
  ];

  // 计算出商品的总金额
  double amount = 0;
  for (var i = 0; i < carts.length; i++) {
    Map cart = carts[i];
    if (cart['selected']) {
      amount += cart['price'] * cart['count'];
    }
  }
  print('总金额：$amount');

  // 记录总金额
  double totalAmount = 0.0;
  // 遍历购物车数据
  carts.forEach((element) {
    // 读取商品的勾选状态
    bool selected = element['selected'];
    // 如果商品被勾选 ，读取该商品的单价和数量，并计算价格小计
    if (selected) {
      double amount = element['count'] * element['price'];
      // 累加价格小计，计算总价
      totalAmount += amount;
    }
  });

  print(totalAmount);
}
